//初始化列表数组
var List = [];
var startDate = '';
var endDate = '';
var editUserId = 0;

//分页查询
var limit = 5;// 每页多少条
var currPage = 1;// 当前页
var allPage = 1;// 总页数
var count = 0;// 默认共多少条数据

var check = 0;
var typeid = 0;
function getstartDate(){
	startDate = document.getElementById('start').value;
    console.log(startDate);
	
}
function getendDate(){
	endDate = document.getElementById('end').value;
    console.log(endDate);
}

function change2(){
    check = $('#check').val();
    console.log(check);
}

gettypelist();
function gettypelist(){
    $.ajax({
		url:ajax_host+'comboBoxType.act',
        dataType:'JSON',
    	success:function(resp){
    		if(resp.success){
                type = resp.list;
				console.log("列表："+type);
				renderType(type);
    		}else{
                layer.alert('获取类型失败')
            }
    	},
    	
    });
    
}
function renderType(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].tId}">${arr[i].tName}</option>`;
	}
	html('type',str);
}

function change(){
    typeid = val('type');
    console.log('类型id：'+typeid);
} 

getMyLogistics();
function getMyLogistics(){
	console.log(startDate);
	console.log(endDate);
    console.log(check);
   
   

	$.ajax({
		url:ajax_host+'getLogistics.act',
		dataType : 'JSON',
		data:{
			start : startDate,
			end : endDate,
			startpage : currPage,
            limitpage : limit,
			check : check,
			typeid : typeid
		},
		success:function(resp){
			
			if(resp.success){
				List = resp.list;
				console.log("查询后列表："+List);
				renderTable(resp.list);
				// 总页数=记录数/每页记录
				count = resp.count;
				console.log('总记录数:'+count)
				allPage=count%limit==0?(count/limit):(parseInt(count/limit+1));
				console.log('总页数:'+allPage);
				$("#pager").html(currPage+"/"+allPage);
			}else{
				layer.alert(resp.errmsg);
			}
        }
	})
}

function renderTable(arr){
	var str = `<tr>
		<th>快件单号</th>
		<th>快件名</th>
        <th>收件人</th>
        <th>审核状态</th>
        <th>快件目的地</th>
      
		
	</tr>`;
	for(var i = 0;i<arr.length;i++){
		var a = arr[i];
		str += 
		   `<tr>
			<td>${a.eId}</td>
			<td>${a.eName}</td>
            <td>${a.aTtn}</td>
            <td>`;
			if(a.cId == 1) str +='待审核';
            if(a.cId == 2) str +='审核通过';
            if(a.cId == 3) str +='审核不通过';
			str +=`</td>
            <td>${a.dest}</td>
			
		</tr>`;
		
	}
	html('table',str);
}


function doAdd(){
    $('#doAdd').modal({
        show:true,//展示出来
        moveable:true,//可移动
        rememberPos:true,//记住移动位置
        backdrop:'static'//背景遮罩
    });
}
function confirm(){
    $('#doAdd').modal('hide', 'fit')
}

function doUpdate(){
    $('#doUpdate').modal({
        show:true,//展示出来
        moveable:true,//可移动
        rememberPos:true,//记住移动位置
        backdrop:'static'//背景遮罩
    });

}

function confirm2(){
    $('#doUpdate').modal('hide', 'fit')
}


function pagenext() {
	if (currPage + 1 > allPage) {
		layer.alert("当前已经是最后一页");
		return;
	}
	
	currPage = currPage + 1;
	getMyLogistics();
};

function pageback() {
	if (currPage - 1 == 0) {
		layer.alert("当前已经是第一页");
		return;
	}
	
	currPage = currPage - 1;
	getMyLogistics();
};
